#include "npc3bomb.h"
#include "../common.h"

namespace fireplane{

	Npc3Bomb::Npc3Bomb( EffectType type ):
		Effect(type)
	{}

	Npc3Bomb::~Npc3Bomb()
	{}

	void Npc3Bomb::init(CreateCmd* cmd)
	{
		CreateNpc2Bomb* tcmd = (CreateNpc2Bomb*)cmd;
		char buffer[0xff];
		CCPoint pos = tcmd->worldPos;

		pos = Effect::getAllEffectParent()->convertToNodeSpace(pos);

		for(int i = 0 ; i < 2 ; i++) _bomb[i] = NULL;
		for(int i = 0 ; i < 2 ; i++){
			sprintf(buffer,"effect/npc3bomb/%d.png",i);
			_bomb[i] = CCSprite::create(buffer);
			addChild(_bomb[i]);
			this->setPosition(pos);
			//this->setScale(0.6f);
		}

		for(int i = 0 ; i < 2 ; i++){
			
			_bomb[i]->runAction(CCScaleTo::create(1.0f,6.0f));
			_bomb[i]->runAction(
				CCSequence::create(
				CCFadeOut::create(1.0f),
				CCCallFunc::create(this,callfunc_selector(Npc3Bomb::destroyThis)),
				NULL));
		}

		scheduleUpdate();
	}

	void Npc3Bomb::destroyThis()
	{
		this->removeFromParentAndCleanup(true);
	}

	void Npc3Bomb::update( float delta )
	{
		for(int i = 0 ; i < 2 ; i++){
			if(_bomb[i]->numberOfRunningActions() == 0){
				destroyThis();
			}
		}
	}
}